package keeto.com.vn.bms.network.task;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.IBMSProtocol;
import keeto.com.vn.bms.network.request.SetReadMessageRequest;
import keeto.com.vn.bms.network.response.SetReadMessageResponse;
import keeto.com.vn.bms.utils.BMSListener;

public class TaskSetReadMessage extends AbstractTask {
	private String MsgId;
	private String Authkey;
	

	public TaskSetReadMessage(BMSListener listener, IBMSCore core,
			String msgId, String authkey) {
		super(listener, core);
		this.MsgId = msgId;
		this.Authkey = authkey;
	}


	@Override
	public void run() throws ClientProtocolException, JSONException,
			IOException {
		// TODO Auto-generated method stub
		SetReadMessageRequest request = new SetReadMessageRequest();
		request.setId(MsgId);
		request.setAuthkey(Authkey);
		SetReadMessageResponse response = protocol.sendReadMessage(request);
		for(BMSListener mListener:listener){
			mListener.finishSendReadMessage(response.getReturnCode(),response.getResultMsg());
		} 
	}

	@Override
	public void timeoutCallback() {
		// TODO Auto-generated method stub
		for(BMSListener mListener:listener){
			mListener.finishSendReadMessage(IBMSProtocol.STATUS_CODE_GENERIC_FAIL_CONECTTION,null);
		} 
	}

}
